package zuoye11;

import java.util.ArrayList;
import java.util.Random;

public class jiang  extends  Thread{
    public  static ArrayList<Integer> list= new ArrayList<>();
   public  static  boolean flag=false;
   public static final Object lock=new Object();
    static{
        synchronized (lock) {
            list.add(10);
            list.add(6);
            list.add(500);
            list.add(2);
            list.add(80);
            list.add(300);
            list.add(20);
            list.add(50);
            list.add(200);
            list.add(800);
        }
    }
   public void run(){
       Random rc = new Random();

       synchronized(lock){
           try {
               Thread.sleep(100);
           } catch (InterruptedException e) {
               throw new RuntimeException(e);
           }
       while(!flag) {
           lock.notifyAll();
           int i = 0;
           if (list.size() > 1) {
               i = rc.nextInt(list.size() - 1);
           }
           if (list.isEmpty()) {
               flag = true;
               break;
           } else
               System.out.println(Thread.currentThread().getName() + " 产生了一个" + list.get(i) + "元大奖");
           list.remove(i);
           try {
               lock.wait();
           } catch (InterruptedException e) {
               throw new RuntimeException(e);
           }
       }
       }
   }
   }

